limsSample.batchChoosePage = {

    getGridParam : function() {
        var _this = this, columns = limsSample.getBatchChooseListColumns();
        _this.param.single ? columns.unshift({
            radio : true
        }) : columns.unshift({
            checkbox : true
        });
        let productFilter = {
            type_EQ: 'TJ',
            status_EQ: '1'
        }
        if (_this.param.type){
            productFilter.type_EQ = _this.param.type
        }
        return {
            type : 'grid',
            id : 'lims-batch-sample-choose-list-grid',
            url : limsSample.baseUrl + '/queries/batch-choose/sample',
            requestData : _this.param,
            page : true,
            filterOpen : true,
            columns : columns,
            toolbar : [ {
                type : 'button',
                text : 'GIKAM.BUTTON.CONFIRM',
                icon : 'select',
                onClick : function() {
                    let selections = Gikam.getComp('lims-batch-sample-choose-list-grid').getSelections();
                    let form = Gikam.getComp('lims-batch-sample-project-choose-form');
                    if (Gikam.isEmpty(selections)) {
                        Gikam.alert('GIKAM.TIP.CHOOSE_AT_LEAST_ONE_ITEM');
                        return;
                    }
                    if (!form.validate()) return;
                    let product = form.getData();
                    product.rows = selections;
                    console.log(product);
                    Gikam.getLastModal().close(product);
                    // Gikam.getLastModal().window.showMask();
                    // Gikam.postText(limsBatch.batchSampleUrl + '/sample/choose', Gikam.getJsonWrapper({
                    //     batchId : _this.param.batchId,
                    //     productCode : product.productCode
                    // }, [null, selections])).done(function () {
                    //     Gikam.getComp('batch-sample-list-grid').refresh();
                    //     Gikam.getComp('logistics-info-grid').refresh();
                    //     Gikam.getLastModal().close();
                    // }).fail(function () {
                    // }).always(function () {
                    //     Gikam.getLastModal() && Gikam.getLastModal().window.closeMask();
                    // });
                }
            },{
                type : 'button',
                text : 'GIKAM.TITLE.CHOOSE.SEARCH',
                icon : 'select',
                onClick : function () {
                    Gikam.create('modal',{
                        title : 'GIKAM.TITLE.CHOOSE.SEARCH',
                        height : 400,
                        width : 400,
                        url : limsSample.baseUrl + '/page/sample-select'+Gikam.param({
                            type : 'sample'
                        }),
                        onAfterClose : function (data) {
                            if (Gikam.isEmpty(data)){
                                return;
                            }
                            let items = data.sampleCode.replace(/[(\r\n)|(\ +)|(，)|(；)|(;)]/g,',');
                            Gikam.post(limsSample.baseUrl + '/queries',Gikam.getJsonWrapper({
                                f : {
                                    sampleCode_IN : items
                                }
                            })).done(function (data) {
                                Gikam.getComp('lims-batch-sample-choose-list-grid').loadData(data.rows);
                            })
                        }
                    })
                }
            },{
                type: 'form',
                id: 'lims-batch-sample-project-choose-form',
                fields: [{
                    field: 'productCode',
                    title: 'T_LIMS_PRODUCT_MAIN.PRODUCTNAME',
                    validators: ['notEmpty'],
                    refreshGrid: false,
                    inputWidth: 180,
                    type: 'select',
                    category: 'product',
                    multiple: true,
                    search: true,
                    firstBlank: false,
                    param: productFilter
                }]
            }]
        }
    },

    create : function() {
        var _this = this;
        Gikam.create('layout', {
            id : 'lims-batch-sample-choose-list-layout',
            renderTo : Gikam.getLastModal().window.$dom,
            center : {
                items : [ this.getGridParam() ]
            }
        });
    },

    init : function(param) {
        this.param = param;
        this.create();
    }
};
